// import path from "path"
import { createWebHashHistory, createRouter } from "vue-router"
// import type { RouteRecordRaw } from "vue-router"

const routes = [
	{
		path: "/",
		component: () => import("../views/index.vue"),
		children: [
			{ path: "", component: () => import("../views/index/index.vue"), meta: { title: "首页" } },
			{ path: "order-list", component: () => import("../views/order-list/index.vue"), meta: { title: "订单列表" } },
			{ path: "user-admin", component: () => import("../views/user-admin/index.vue"), meta: { title: "用户管理" } },
			{ path: "system-admin", component: () => import("../views/system-admin/index.vue"), meta: { title: "系统管理" } },
		],
	},
]

// 创建路由
const router = createRouter({
	history: createWebHashHistory(),
	routes,
})

// 设置下一级路由的文档标题
router.beforeEach(async (to, _, next) => {
	const baseTitle = "某某网站"
	if (to.meta.title) {
		document.title = `${to.meta.title} - ${baseTitle}`
	} else {
		document.title = baseTitle
	}
	next()
})

export default router
